Skip to content

btcjson: prevent infinite recursion in StringOrArray.MarshalJSON and … #2370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cvieira-tng
Copy link

Fix #2369

Change Description

Fix an infinite-recursion bug in btcjson.StringOrArray.MarshalJSON that
caused a stack-overflow panic at runtime.

  • Switch receiver from value to pointer so we no longer call the same method
    on a copy of the slice (which re-enters indefinitely).
  • Add unit tests (TestGetNetworkInfoWarnings) to cover single-string and
    slice cases as well as malformed input.
  • No external API changes.

Closes #.


Steps to Test

  1. Build & test
    go test ./...          # all packages pass  

2. **Reproduce the old panic (optional)**

   ```bash
   git checkout HEAD^            # commit before this PR  
   go test -run TestGetNetworkInfoWarnings ./btcjson  # panic  
   ```

   Returning to this PR’s head makes the test suite pass again.

---

## Pull Request Checklist

### Testing

* [x] Your PR passes all CI checks.
* [x] Tests covering the positive and negative (error paths) are included.
* [x] Bug fixes contain tests triggering the bug to prevent regressions.

### Code Style and Documentation

* [x] The change is not
  [[insubstantial](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#substantial-contributions-only)](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#substantial-contributions-only).
* [x] The change obeys the
  [[Code Documentation and Commenting](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#code-documentation-and-commenting)](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#code-documentation-and-commenting)
  guidelines, and lines wrap at 80.
* [x] Commits follow the
  [[Ideal Git Commit Structure](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#model-git-commit-messages)](https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md#model-git-commit-messages).
* [x] Any new logging statements use an appropriate subsystem and logging
  level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: StringOrArray.MarshalJSON triggers infinite recursion → stack-overflow panic
1 participant